//package cn.bonoon.kernel.support;
//
//import cn.bonoon.kernel.descriptors.DescriptorFactory;
//import cn.bonoon.kernel.descriptors.EntityDescriptor;
//import cn.bonoon.kernel.support.entities.Persistable;
//
//public class BaseSearcher {
//    /**
//	 * 是否有order by的限制，如果有，则其它的排序将无法起效
//	 */
//	protected String order = "";
//    protected boolean allowAppendOrder = true;
//	
//    protected String where = "";
//    protected final String from;
////    protected final Class<? extends Persistable> entityClass;
//	public final EntityDescriptor entityDescriptor;
//	
//	public BaseSearcher(Class<? extends Persistable> entityClass){
//		this.entityClass = entityClass;
//		this.entityDescriptor = DescriptorFactory.entityDescriptor(entityClass);
//		this.from = " from " + entityClass.getName() + " x ";
//	}
//	
////	public void order(){
////		allowAppendOrder = false;
////		order = "x.ordinal asc";
////	}
////	public void defaultOrder() {
////		order = "x.id asc";
////	}
////	public void deletable(){
////		where = " where x.deleted=false";
////	}
////	public void where(){
////		where = " where 1=1";
////	}
////	
//	public void init(){
//		if(entityDescriptor.is(EntityDescriptor.MOVABLE)){
//			allowAppendOrder = false;
//			order = "x.ordinal asc";
////		}else{
////			order = "x.id asc";
//		}
//		
//		if(entityDescriptor.is(EntityDescriptor.DELETABLE)){
//			where = " where x.deleted=false";
//		}else{
//			where = " where 1=1";
//		}
//	}
//	
//	public StandardFinder initFinder(StandardFinder finder){
//		finder.from.append(from);
//		finder.where.append(where);
//		finder.orderby.append(order);
//		finder.allowAppendOrder = allowAppendOrder;
//		return finder;
//	}
//	
//	public StandardFinder finder(ProxyEntityManager manager){
//		return initFinder(new StandardFinder(manager));
//	}
//	
//	public String orderby(){
//		return " order by " + (order.trim().isEmpty() ? "x.id desc" : order);
//	}
//	
//	public String selectAllEntities(){
//		return from + where;// + " order by " + order;
//	}
//	
//	public String selectTreeRoot(){
//		return from + where + " and x.parent is null";// order by " + order;
//	}
//	
//	public String selectTreeChildren(){
//		return from + where + " and x.parent.id=?";// order by " + order;
//	}
//}
